package com.eric.enderslastgame;

import java.util.ArrayList;
import java.util.Timer;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;

public class Minimap {

	private Timer repaintTimer;
	private Human human;
	private ArrayList<Bugger> buggers;
	private Paint textPaint;

	private int id;

	public Minimap(Human human, ArrayList<Bugger> buggers, int id) {
		super();

		this.id = id;

		this.human = human;
		this.buggers = buggers;

		textPaint = new Paint();
		textPaint.setColor(Color.WHITE);
		textPaint.setStyle(Style.FILL);
	}

	public void draw(Canvas canvas) {

		if (EndersGamePanel.inGame) {
			if (human != null && buggers != null) {

				for (Bugger i : buggers) {
					// Translate position coordinates to be scaled onto the
					// Minimap
					double x = (1.0 / (double) (EndersGamePanel.sets - 1))
							* i.getX();
					double y = (EndersGamePanel.MINIMAP_HEIGHT_FRACTION / EndersGamePanel.BOARD_HEIGHT_FRACTION)
							* (double) i.getY();
					canvas.drawBitmap(i.getMiniBitmap(),
							convertToMinimapX(i.getX()),
							convertToMinimapY(i.getY()), null);
				}

				// Translate position coordinates to be scaled onto the Minimap
				double x = (1.0 / (double) (EndersGamePanel.sets - 1))
						* human.getX();
				double y = (EndersGamePanel.MINIMAP_HEIGHT_FRACTION / EndersGamePanel.BOARD_HEIGHT_FRACTION)
						* (double) human.getY();
				canvas.drawBitmap(human.getMiniBitmap(), (int) x, (int) y, null);

				if (human.incoming) {
					canvas.drawText("Incoming", convertToMinimapX(0), convertToMinimapY(0), textPaint);
				}
			} else {
			}
		} else {
		}
	}

	public void setHuman(Human human) {
		this.human = human;
	}

	public void setBuggers(ArrayList<Bugger> buggers) {
		this.buggers = buggers;
	}

	public Human getHuman() {
		return human;
	}

	public ArrayList<Bugger> getBuggers() {
		return buggers;
	}

	public int convertToMinimapX(int x) {
		return x / EndersGamePanel.sets * (id + 1);
	}

	public int convertToMinimapY(int y) {
		return (int) (y
				* (EndersGamePanel.MINIMAP_HEIGHT_FRACTION / EndersGamePanel.BOARD_HEIGHT_FRACTION) + EndersGamePanel.MINIMAP_HEIGHT_FRACTION
				* EndersGamePanel.panelHeight);
	}
}
